﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
extern alias pcl;
using System;
using Moq;
using pcl::System.Security.Cryptography;
using pcl::System.Security.Cryptography.Adaptation;

namespace Portable
{
    internal class ISymmetricAlgorithmFactory : MockFactory<ISymmetricAlgorithm>
    {
        public static ISymmetricAlgorithm OverrideKey(Func<byte[]> action)
        {
            var mock = CreateMock();
            mock.SetupGet(a => a.Key)
                .Returns(action);

            return mock.Object;
        }

        public static ISymmetricAlgorithm OverrideKey(Action<byte[]> action)
        {
            var mock = CreateMock();
            mock.SetupSet(a => a.Key = It.IsAny<byte[]>())
                .Callback(action);

            return mock.Object;
        }

        public static ISymmetricAlgorithm OverrideIV(Func<byte[]> action)
        {
            var mock = CreateMock();
            mock.SetupGet(a => a.IV)
                .Returns(action);

            return mock.Object;
        }

        public static ISymmetricAlgorithm OverrideIV(Action<byte[]> action)
        {
            var mock = CreateMock();
            mock.SetupSet(a => a.IV = It.IsAny<byte[]>())
                .Callback(action);

            return mock.Object;
        }

        public static ISymmetricAlgorithm OverrideCreateEncryptor(Func<byte[], byte[], ICryptoTransform> action)
        {
            var mock = CreateMock();
            mock.Setup(a => a.CreateEncryptor(It.IsAny<byte[]>(), It.IsAny<byte[]>()))
                .Returns(action);

            return mock.Object;
        }

        public static ISymmetricAlgorithm OverrideCreateDecryptor(Func<byte[], byte[], ICryptoTransform> action)
        {
            var mock = CreateMock();
            mock.Setup(a => a.CreateDecryptor(It.IsAny<byte[]>(), It.IsAny<byte[]>()))
                .Returns(action);

            return mock.Object;
        }
    }
}
